<?php
namespace app\index\logic;
use think\Db;

class Faq
{
    public function getList($params)
    {
        $params['page']     = isset($params['Pages']) ? $params['Pages'] : 1;
        $params['limit']    = isset($params['Size']) ? $params['Size'] : 20;

        $where[] = ['uid','=',request()->userInfo['id']];
        $where[] = ['from_id','<',1];
        $where[] = ['type','=',1];

        $orderBy = ['id' => 'DESC'];

        $FaqModel = \think\facade\App::model('Faq', 'model');
        $list = $FaqModel->getList($where,'id,content,from_id,tel,faq_type',$params['page'],$params['limit'],$orderBy);

        $data = [];
        if($list)
        {
            $id_gh = array_column($list,'id');
            $replys = Db::table('quick_faq')->where('type',2)
                    ->where('from_id','in',$id_gh)->column('from_id,content,create_time');

            foreach ($list as $k=>$v)
            {
                $data[$k]['id']         = $v['id'];
                $data[$k]['content']    = $v['content'];
                $data[$k]['tel']        = $v['tel'];
                $data[$k]['faq_type']   = $v['faq_type'];
                if(isset($replys[$v['id']]))
                {
                    $data[$k]['reply'] = ['content' => $replys[$v['id']]['content'], 'create_time'=> $replys[$v['id']]['create_time'] ];
                }else{
                    $data[$k]['reply'] = [];
                }

            }

        }

        $result['total']    = $FaqModel->getTotalNumber($where);
        $result['list']     = $data;

        return $result;
    }

}